#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  cin >> n;

  vector<vector<int>> shelf(n, vector<int>(3));
  for (int i = 0; i < n; i++) {
    cin >> shelf[i][0] >> shelf[i][1] >> shelf[i][2];
  }

  // dp[i][mask] 表示前i个货架，使用mask表示已选面包类型的最小移动次数
  // mask: 0b001(1)=蛋糕, 0b010(2)=甜甜圈, 0b100(4)=羊角面包
  vector<vector<int>> dp(n, vector<int>(8, INT_MAX));

  // 初始化第一个货架
  int total = shelf[0][0] + shelf[0][1] + shelf[0][2];
  dp[0][1] = total - shelf[0][0]; // 选择蛋糕
  dp[0][2] = total - shelf[0][1]; // 选择甜甜圈
  dp[0][4] = total - shelf[0][2]; // 选择羊角面包

  for (int i = 1; i < n; i++) {
    total = shelf[i][0] + shelf[i][1] + shelf[i][2];
    vector<int> new_dp(8, INT_MAX);

    for (int mask = 0; mask < 8; mask++) {
      if (dp[i - 1][mask] == INT_MAX)
        continue;

      // 选择蛋糕
      new_dp[mask | 1] =
          min(new_dp[mask | 1], dp[i - 1][mask] + (total - shelf[i][0]));

      // 选择甜甜圈
      new_dp[mask | 2] =
          min(new_dp[mask | 2], dp[i - 1][mask] + (total - shelf[i][1]));

      // 选择羊角面包
      new_dp[mask | 4] =
          min(new_dp[mask | 4], dp[i - 1][mask] + (total - shelf[i][2]));
    }
    dp[i] = new_dp;
  }

  // 必须包含所有三种面包 (mask=7)
  cout << dp[n - 1][7] << endl;
  return 0;
}
